﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="LogExport.aspx.vb" Inherits="Map.LogExport" %>

<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
    <link rel="stylesheet" type="text/css" href="/_common/styles/select.css">
    <link rel="stylesheet" type="text/css" href="/_nav/menu.css">
    <link rel="stylesheet" type="text/css" href="/_nav/tabs.css">
    <link rel="stylesheet" type="text/css" href="/_nav/nav.css">
    <link rel="stylesheet" type="text/css" href="/_grid/map_grid.css">
    <link rel="stylesheet" type="text/css" href="/_forms/styles/form.css">

    <script language="javascript" src="/_common/scripts/global.js"></script>
    <script language="javascript" src="/_common/scripts/Details.js"></script>
    <script language="javascript" src="/_controls/settings.aspx"></script>
    <script language="javascript" src="/_controls/util/util.js"></script>
    <script language="javascript" src="/_controls/datetime/date.js"></script>
    <script language="javascript" src="/_controls/datetime/time.js"></script>
    <script language="javascript" src="/_controls/number/number.js"></script>
    <script language="javascript" src="/_controls/lookup/map_lookup.js"></script>
    <script language="javascript" src="/_controls/find/find.js"></script>
    <script language="javascript" src="/_nav/menu.js"></script>
    <script language="javascript" src="/_forms/FormBase.js"></script>

    <%--日志管理系统的公用JS--%>
    <script src="Js/LMSCommon.js" type="text/javascript"></script>
</head>
<body ms_positioning="GridLayout" style="padding: 10px;" onload="win_onload()">
    <form id="Form1" runat="server" method="post" enableviewstate="false">
        <asp:Literal ID="Content" runat="server"></asp:Literal>
    </form>
    <table style="font-size: 9pt;" height="100%" cellspacing="0" cellpadding="0" width="100%">
        <tr height="1">
            <td>
                <mnu:AppFormMenu ID="appFormMenu" runat="server"></mnu:AppFormMenu>
            </td>
        </tr>
        <tr>
            <td style="height: 5px">
                &nbsp;
            </td>
        </tr>        
        <tr>
            <td>
                <cnt:AppForm ID="appForm" runat="server" ProcessType="xmlhttp"  OnBeforeSave="oprBeforeSave()" OnAfterSave ="oprAfterSave()">
                </cnt:AppForm>
            </td>
        </tr>
    </table>
</body>
</html>

<script type="text/javascript">

    //录入字符数校验
    function CheckInputLength(v, maxlen)
    {
        if (maxlen && !isNaN(maxlen))
        {
            if (v.value.length > maxlen * 1)
            {
                alert("录入字符不允许超过"+maxlen+"个字符。");
                v.select();
                event.returnValue = false;
            }
        }
    }

    function oprBeforeSave()
    {
        var xmlDom = XMLDOM();
        xmlDom.loadXML(__xml);
        if (xmlDom.parseError.errorCode != 0)
        {
            alert("导出日志文件失败！");
            event.returnValue = false;
            return;
        }

        var startDate = appForm.StartDate;  //开始日期
        var endDate = appForm.EndDate;      //结束日期
        var enableLatestTime ;              //有效采集最早时间
        var enableRecentTime;               //有效采集最近时间

        xmlNode = xmlDom.documentElement.selectSingleNode("/times/enablerecenttime");
        if (xmlNode != null)
        {
            enableRecentTime = xmlNode.text;
        }
        
        xmlNode = xmlDom.documentElement.selectSingleNode("/times/enablelatesttime");
        if (xmlNode != null)
        {
            enableLatestTime = xmlNode.text;
        }

        if (!enableLatestTime || !enableRecentTime )
        {
            alert("无采集数据，不能导出！");
            event.returnValue = false;
            return;
        }

        /*
        去掉导出时间限制
        if (!startDate || !endDate || !enableLatestTime || !enableRecentTime || startDate.value == "" || endDate.value == "")
        {
        alert("开始日期和截止日期必须在有效最早采集时间和有效最近采集时间范围内！");
        event.returnValue = false;
        return;
        }
        */

        if (startDate.value && endDate.value)
        {
            var result = compareDate(startDate.value, endDate.value);
            if (result == 1)
            {
                alert("开始日期必须小于截止日期！");
                event.returnValue = false;
                return;
            }
        }

        var userxml = "<times>";
            userxml += "<begintime>" + startDate.value + "</begintime>"
            userxml += "<endtime>"   + endDate.value + "</endtime>"
            userxml += "<enablerecenttime>" + enableRecentTime + "</enablerecenttime>"
            userxml += "<enablelatesttime>" + enableLatestTime + "</enablelatesttime>"
            userxml += "</times>"

            appForm.userxml = userxml;
        }

        function oprAfterSave()
        {
            var xmlDom = XMLDOM();
            xmlDom.loadXML(appForm.returnxml);

            if (xmlDom.parseError.errorCode != 0) return "";

            if (xmlDom.documentElement && xmlDom.documentElement.attributes.getNamedItem("result").value == "true")
            {
                if (xmlDom.documentElement.attributes.getNamedItem("result") != null)
                {
                    var filename = xmlDom.documentElement.attributes.getNamedItem("filename").value;
                    openStdWin("/LMS/DownLoadExportZipFile.aspx?file=" + escape(filename), "日志导出下载", 450, 140);
                }
            }
            else
            {
                alert(xmlDom.documentElement.attributes.getNamedItem("errormessage").value);
            }
        }

    function win_onload()
    {

        HideMenu();
        appForm._bAlert = false;
        
        var xmlDom = XMLDOM();
        xmlDom.loadXML(__xml);
        if (xmlDom.parseError.errorCode != 0) return;

        var enableLatestTime = document.getElementById("appForm_EnableLatestTime"); //有效采集最早时间
        var enableRecentTime = document.getElementById("appForm_EnableRecentTime"); //有效采集最近时间

        var startDate = appForm.StartDate;
        var endDate = appForm.EndDate;
        var xmlNode;

        if (startDate && endDate)
        {
            xmlNode = xmlDom.documentElement.selectSingleNode("/times/begintime");
            startDate.setValue(xmlNode.text);

            xmlNode = xmlDom.documentElement.selectSingleNode("/times/endtime");
            endDate.setValue(xmlNode.text);
        }

        if (enableLatestTime && enableRecentTime)
        {
            xmlNode = xmlDom.documentElement.selectSingleNode("/times/enablerecenttime");
            if (xmlNode != null)
            {
                enableRecentTime.innerText += xmlNode.text;
            }

            xmlNode = xmlDom.documentElement.selectSingleNode("/times/enablelatesttime");
            if (xmlNode != null)
            {
                enableLatestTime.innerText += xmlNode.text;
            }
        }
    }
</script>

